package com.dyz.swordFingerOffer;

/**
 * @author: daiyizheng
 * @date: 2021/6/5 13:33
 * @description:
 */
public class NumberOf1Between1AndN_Solution43 {
    public int NumberOf1Between1AndN_Solution(int n) {
        if(n<0){
            return 0;
        }
        int count = 0;

        for (int i = 1; i <= n; i++) {
            count += numberOf1(i);
        }
        return count;

    }
    private static int numberOf1(int n) {
        int count = 0;
        while (n > 0) {
            if (n % 10 == 1) {
                ++count;
            }
            n = n / 10;
        }
        return count;
    }
}
